var e = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), t = require("../../../@babel/runtime/helpers/asyncToGenerator"), a = getApp(), r = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ r ],
    data: {
        order_id: 0,
        location: {},
        detailInfo: {},
        pictureShow: !1,
        pictureList: [],
        codeShow: !1,
        codeText: "",
        takeCodeImageUrl: "",
        custom_name: ""
    },
    onLoad: function(e) {
        var t = this;
        if (e.order_id && (this.data.order_id = e.order_id), e.scene) {
            var a = decodeURIComponent(e.scene);
            if (console.log(a), a) {
                var r = [];
                r = a.split("&");
                for (var n = 0; n < r.length; n++) {
                    var i;
                    i = r[n].split("="), console.log(i), "order_id" == i[0] && this.setData({
                        order_id: i[1]
                    });
                }
            }
        }
        this._getLocation(function(e, a) {
            t.setData({
                "location.latitude": a.lat,
                "location.longitude": a.lng,
                "location.address": e.address
            }), t.getDetails();
        });
    },
    setPictureShow: function() {
        this.setData({
            pictureShow: !this.data.pictureShow
        });
    },
    setCodeShow: function() {
        this.setData({
            codeShow: !this.data.codeShow
        });
    },
    makePhoneCall: function(e) {
        var t = this.data.detailInfo.mobile;
        wx.makePhoneCall({
            phoneNumber: t
        });
    },
    openLocation: function(e) {
        var t = this.data.detailInfo, a = t.latitude, r = t.longitude;
        wx.openLocation({
            latitude: Number(a),
            longitude: Number(r)
        });
    },
    onReady: function() {},
    getDetails: function() {
        var e = this, t = this.data, r = t.order_id, n = t.location, i = a.getNetAddresss("plugin.live-install.frontend.worker-order.orderDetail");
        a._postNetWork({
            url: i,
            data: {
                order_id: r,
                longitude: n.longitude,
                latitude: n.latitude
            },
            success: function(t) {
                var r = t.data;
                if (1 != r.result) return a.tips(r.msg);
                r.data.another_name && r.data.another_name.worker_name && wx.setNavigationBarTitle({
                    title: r.data.another_name.worker_name
                }), e.setData({
                    detailInfo: r.data,
                    custom_name: r.data.another_name.custom_name || "安装"
                });
            }
        });
    },
    onShow: function() {},
    onHide: function() {},
    bindPreviewImage: function(e) {
        var t = e.currentTarget.dataset, a = t.arr, r = t.src;
        wx.previewImage({
            urls: a,
            current: r
        });
    },
    onUnload: function() {},
    onPullDownRefresh: function() {},
    bindBtnClick: function(r) {
        var n = this;
        return t(e.default.mark(function t() {
            var i, o, s, d;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    if (console.log(r), i = r.currentTarget.dataset, o = i.item, s = i.order_id, n.data._order_id = s, 
                    "installFinish" != o.code) {
                        e.next = 8;
                        break;
                    }
                    return n.setPictureShow(), e.abrupt("return");

                  case 8:
                    if ("workerChoose" != o.code) {
                        e.next = 16;
                        break;
                    }
                    return e.next = 11, a.confirm("确定抢单吗？");

                  case 11:
                    if (0 != e.sent) {
                        e.next = 14;
                        break;
                    }
                    return e.abrupt("return");

                  case 14:
                    e.next = 22;
                    break;

                  case 16:
                    if ("installStart" != o.code) {
                        e.next = 22;
                        break;
                    }
                    return e.next = 19, a.confirm("确定".concat(o.name, "?"));

                  case 19:
                    if (0 != e.sent) {
                        e.next = 22;
                        break;
                    }
                    return e.abrupt("return");

                  case 22:
                    d = a.getNetAddresss(o.api), a._postNetWork({
                        url: d,
                        data: {
                            order_id: s,
                            source: 2
                        },
                        success: function(e) {
                            var t = e.data;
                            if (a.tips(t.msg), 1 === t.result) if ("takeCode" == o.code) {
                                n.setData({
                                    takeCodeImageUrl: t.data,
                                    codeShow: !0,
                                    codeText: "取货码"
                                });
                            } else n.getDetails();
                        }
                    });

                  case 24:
                  case "end":
                    return e.stop();
                }
            }, t);
        }))();
    },
    getPayCode: function() {
        var e = this, t = this.data.detailInfo.order_id, r = a.getNetAddresss("plugin.live-install.frontend.worker-order.payCode");
        a._postNetWork({
            url: r,
            data: {
                order_id: t,
                source: 2
            },
            success: function(t) {
                var r = t.data;
                if (1 !== r.result) return a.tips(r.msg);
                e.setData({
                    takeCodeImageUrl: r.data,
                    codeShow: !0,
                    codeText: "收款码"
                });
            }
        });
    },
    sendImageBtn: function() {
        var e = this, t = this.data, r = t.pictureList, n = t._order_id;
        if (0 == r.length) return a.tips("请上传".concat(this.data.custom_name, "图片"));
        var i = a.getNetAddresss("plugin.live-install.frontend.worker-order.finishInstall");
        a._postNetWork({
            url: i,
            data: {
                order_id: n,
                image: r
            },
            success: function(t) {
                var r = t.data;
                if (1 !== r.result) return a.tips(r.msg);
                e.setPictureShow(), e.getDetails();
            }
        });
    },
    bindAfterBtnClick: function(r) {
        var n = this;
        return t(e.default.mark(function t() {
            var i, o, s, d;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    if (i = r.currentTarget.dataset, o = i.btn, s = i.refund_id, "finishRefund" != o.code) {
                        e.next = 7;
                        break;
                    }
                    return e.next = 4, a.confirm("是否确定".concat(o.name));

                  case 4:
                    if (0 != e.sent) {
                        e.next = 7;
                        break;
                    }
                    return e.abrupt("return");

                  case 7:
                    d = a.getNetAddresss(o.api), a._postNetWork({
                        url: d,
                        data: {
                            refund_id: s
                        },
                        success: function(e) {
                            var t = e.data;
                            a.tips(t.msg), 1 === t.result && n.getDetails();
                        }
                    });

                  case 9:
                  case "end":
                    return e.stop();
                }
            }, t);
        }))();
    },
    onRead_2: function() {
        var e = this;
        wx.chooseImage({
            count: 9,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                console.log(t.tempFilePaths), e.unload({
                    tempFilePaths: t.tempFilePaths
                });
            }
        });
    },
    unload: function(e) {
        var t = this;
        if (0 != e.tempFilePaths.length) {
            wx.showLoading({
                title: "上传中"
            });
            var r = a.getNetAddresss("upload.uploadPic");
            wx.uploadFile({
                url: r,
                filePath: e.tempFilePaths[0],
                name: "file",
                formData: null,
                success: function(e) {
                    var a = JSON.parse(e.data), r = t.data.pictureList;
                    r.push(a.data.img_url), t.setData({
                        pictureList: r
                    });
                },
                complete: function(a) {
                    wx.hideLoading(), e.tempFilePaths.shift(), t.unload(e);
                }
            });
        }
    },
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            path: "packageH/installationSever/installationSeverDetail/installationSeverDetail?order_id=" + this.data.order_id
        };
    }
});